#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++) 
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int , int >;
using vec = vector < int >;
using veg = vector < pii >;

int read() {
	int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-', ch = getchar(); 
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar(); return f ? -x : x;
}

const int N = 6e5 + 10;
const int mod = 998244353;
const int inv2 = (mod + 1) >> 1;
int n, Q, a[N], x[N], y[N], b[N], ans, tot;

inline int upd(int x) { return x + (x >> 31 & mod); }
inline int pos(int x) { return lower_bound(b + 1, b + tot + 1, x) - b; }

struct BIT {
	int tr[N];
	void add(int x, int v) { for(; x <= tot; x += x & -x) tr[x] = upd(tr[x] + v - mod); }
	int query(int x) { int res = 0; for(; x; x -= x & -x) res = upd(res + tr[x] - mod); return res; }
	int query(int x, int y) { return x > y ? 0 : upd(query(y) - query(x - 1)); }
} T, B;

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in, Q = in; rep(i, 1, n) a[i] = b[++tot] = in; rep(i, 1, Q) x[i] = in, y[i] = b[++tot] = in;
	sort(b + 1, b + tot + 1); tot = unique(b + 1, b + tot + 1) - b - 1;
	rep(i, 1, n) a[i] = pos(a[i]); rep(i, 1, Q) y[i] = pos(y[i]);
	rep(i, 1, n) ans = upd(ans + upd(1ll * T.query(a[i]) * b[a[i]] % mod - B.query(a[i])) - mod), T.add(a[i], 1), B.add(a[i], b[a[i]]),
		ans = upd(ans + upd(B.query(a[i], tot) - 1ll * T.query(a[i], tot) * b[a[i]] % mod) - mod);
	rep(i, 1, Q) {
		int lst = a[x[i]];
		ans = upd(ans - upd(1ll * T.query(lst) * b[lst] % mod - B.query(lst)));
		ans = upd(ans - upd(B.query(lst, tot) - 1ll * T.query(lst, tot) * b[lst] % mod));
		T.add(lst, mod - 1); B.add(lst, mod - b[lst]);
		a[x[i]] = y[i];
		ans = upd(ans + upd(1ll * T.query(y[i]) * b[y[i]] % mod - B.query(y[i])) - mod);
		ans = upd(ans + upd(B.query(y[i], tot) - 1ll * T.query(y[i], tot) * b[y[i]] % mod) - mod);
		T.add(y[i], 1); B.add(y[i], b[y[i]]);
		cout << 1ll * ans * inv2 % mod << endl;
	}
	return 0;
}
